package interview.base;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;


/***
 *    带有返回值的线程
 * **/
class CallableThread implements Callable<Integer>{
    @Override
    public Integer call() throws Exception {
        System.out.println("执行call.....");
        Thread.sleep(2000);
        return 1024;
    }
}

class RunnableThread implements Runnable{
    @Override
    public void run() {
        System.out.println("run............");
    }
}

public class CreateThread {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        FutureTask<Integer>  futureTask = new FutureTask(new CallableThread());

        new Thread(futureTask,"AAA").start();
        int ret1 = 100;
        System.out.println("ret1"+ret1);
        Integer ret2 =  futureTask.get();
        System.out.println("获取完毕");
        System.out.println(ret1+ret2);

        System.out.println("实现二");


    }
}
